Unit FormClassDataList;

Interface

Uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FormClass, FormClassEmptyList, ImgList,
  DB, ADODB, DBTables,
  Menus, ActnList,
  StdCtrls, Buttons, fcLabel, Grids, Wwdbigrd, Wwdbgrid, ExtCtrls,
  fcStatusBar;

Type
  TfmFormClassDataList = Class(TfmFormClassEmptyList)
    acEkle : TAction;
    acKaydet : TAction;
    acGuncelle : TAction;
    acSil : TAction;
    acVazgec : TAction;
    acYenile : TAction;
    miEkle : TMenuItem;
    miKaydet : TMenuItem;
    miGuncelle : TMenuItem;
    miIncele : TMenuItem;
    N1 : TMenuItem;
    miSil : TMenuItem;
    miVazgec : TMenuItem;
    N3 : TMenuItem;
    miYenile : TMenuItem;
    N4 : TMenuItem;
    pnlHizliArama : TPanel;
    btHizliArama : TSpeedButton;
    edArama : TEdit;
    acHizliArama : TAction;
    pnlButtonYeni : TPanel;
    btYeni : TBitBtn;
    pnlButtonSil : TPanel;
    btSil : TBitBtn;
    pnlButtonDuzelt : TPanel;
    btDuzelt : TBitBtn;
    pnlButtonIncele : TPanel;
    btIncele : TBitBtn;
    pnlButtonKaydet : TPanel;
    btKaydet : TBitBtn;
    pnlButtonVazgec : TPanel;
    btVazgec : TBitBtn;
    pnlButtonSec : TPanel;
    btSec : TBitBtn;
    Procedure acEkleExecute(Sender : TObject);
    Procedure aqEntryAfterCancel(DataSet : TDataSet);
    Procedure aqEntryAfterOpen(DataSet : TDataSet);
    Procedure edAramaKeyUp(Sender : TObject; Var Key : Word;
      Shift : TShiftState);
    Procedure FormShow(Sender : TObject);
    Procedure grdListeKeyDown(Sender : TObject; Var Key : Word;
      Shift : TShiftState);
    Procedure FormCreate(Sender : TObject);
  Private
    { Private declarations }
    Procedure ActionKontrol(gState : TDataSetState); Virtual;
  Public
    { Public declarations }

  Protected
    Procedure ButtonWidthCaptionToRunTimeMode; Override;
    Procedure ButtonVisibleToRunTimeMode; Override;
    Procedure DesingFormToTerminal; Override;
  End;

Var
  fmFormClassDataList : TfmFormClassDataList;

Implementation

Uses Boxes, data, Math, UnitOrtak, UnitTeknik;

{$R *.dfm}

Procedure TfmFormClassDataList.ActionKontrol(gState : TDataSetState);
Begin
  acEkle.Enabled := Not (gState In [dsEdit, dsInsert]);
  acKaydet.Enabled := (gState In [dsEdit, dsInsert]);
  acGuncelle.Enabled := Not (gState In [dsEdit, dsInsert]);
  acIncele.Enabled := Not (gState In [dsEdit, dsInsert]);
  acSil.Enabled := Not (gState In [dsEdit, dsInsert]);
  acVazgec.Enabled := (gState In [dsEdit, dsInsert]);
  acYenile.Enabled := Not (gState In [dsEdit, dsInsert]);
  acKapat.Enabled := Not (gState In [dsEdit, dsInsert]);
  {
    grdListe.ReadOnly := Not (gState In [dsEdit, dsInsert]);
    If (gState In [dsEdit, dsInsert]) Then
      grdListe.Options := grdListe.Options + [Wwdbigrd.dgEditing]
    Else
      grdListe.Options := grdListe.Options - [Wwdbigrd.dgEditing];
  }

  If (gState In [dsEdit, dsInsert]) Then
    ControlSetting(Self, clWhite, False)
  Else
    ControlSetting(Self, clInfoBk, True);

  grdListe.ReadOnly := False;
End;

Procedure TfmFormClassDataList.ButtonWidthCaptionToRunTimeMode;
Begin
  btSec.Width := IfThen(RunTimeMode = rtmTerminal, 48, 67);
  btYeni.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btKaydet.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btSil.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btDuzelt.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btVazgec.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btIncele.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btKapat.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);

  btYeni.Caption := IfThen(RunTimeMode = rtmTerminal, '', btYeni.Caption);
  btKaydet.Caption := IfThen(RunTimeMode = rtmTerminal, '', btKaydet.Caption);
  btSil.Caption := IfThen(RunTimeMode = rtmTerminal, '', btSil.Caption);
  btDuzelt.Caption := IfThen(RunTimeMode = rtmTerminal, '', btDuzelt.Caption);
  btVazgec.Caption := IfThen(RunTimeMode = rtmTerminal, '', btVazgec.Caption);
  btIncele.Caption := IfThen(RunTimeMode = rtmTerminal, '', btIncele.Caption);
  btKapat.Caption := IfThen(RunTimeMode = rtmTerminal, '', btKapat.Caption);
End;

Procedure TfmFormClassDataList.ButtonVisibleToRunTimeMode;
Begin
  acEkle.Visible := RunTimeMode = rtmPC;
  acKaydet.Visible := RunTimeMode = rtmPC;
  acSil.Visible := RunTimeMode = rtmPC;
  acVazgec.Visible := RunTimeMode = rtmPC;
  acIncele.Visible := RunTimeMode = rtmPC;
  acGuncelle.Visible := RunTimeMode = rtmPC;
End;

Procedure TfmFormClassDataList.DesingFormToTerminal;
Begin
  Inherited DesingFormToTerminal;
  If RunTimeMode = rtmTerminal Then
  Begin
    pnlHizliArama.Visible := False;
    ButtonWidthCaptionToRunTimeMode;
  End;
End;

Procedure TfmFormClassDataList.acEkleExecute(Sender : TObject);
Begin
  Inherited;
  NavigatorKontrol(aqEntry, TAction(Sender).Tag);
End;

Procedure TfmFormClassDataList.aqEntryAfterCancel(DataSet : TDataSet);
Begin
  Inherited;
  ActionKontrol(DataSet.State);
  ColumnDesign(DataSet.State);
  If aqEntry.Active Then
  Begin
    If aqEntry.RecNo >= 0 Then
      lbNavigatorRecNo.Caption := '[ ' + IntToStr(aqEntry.RecNo) + ' / ' + IntToStr(aqEntry.RecordCount) + ' ]'
    Else
      lbNavigatorRecNo.Caption := '[ 0 / 0 ]';
    paNavigatorRecNo.Left := 30;
    //If aqEntry.State In [dsInsert, dsEdit] Then
    //  grdListe.SetFocus;
  End;
End;

Procedure TfmFormClassDataList.aqEntryAfterOpen(DataSet : TDataSet);
Begin
  Inherited;
  aqEntryAfterCancel(DataSet);
  //if (UseType = futSelect) and (aqEntry.Active) and (aqEntry.RecordCount = 1) then
  //  acSec.Execute;
End;

Procedure TfmFormClassDataList.edAramaKeyUp(Sender : TObject; Var Key : Word;
  Shift : TShiftState);
Var
  l : byte;
  kno : Integer;
  yAdo : TADOQuery;
Begin
  Inherited;
  If Not (dsEntry.DataSet As TADOQuery).Active Then
    Exit;

  If m_szSearchField = '' Then
    Exit;

  If Key = 13 Then
    grdListe.SetFocus;

  yAdo := (dsEntry.DataSet As TADOQuery);
  If ((key > 31) And (key < 123)) Or (key = 8) Then
  Begin
    l := length(edArama.Text);
    If key = 8 Then
      dec(l);

    yAdo.DisableControls;
    kno := yAdo.recno;
    yAdo.First;
    While Not yAdo.EOF Do
    Begin
      If Buyut(copy(yAdo.FieldByName(m_szSearchField).AsString, 1, l)) = Buyut(copy(edArama.Text, 1, l)) Then
        break;
      yAdo.Next;
    End;
    If yAdo.EOF And (Buyut(copy(yAdo.FieldByName(m_szSearchField).AsString, 1, l)) <> Buyut(copy(edArama.Text, 1, l))) Then
      yAdo.recno := kno
    Else
    Begin
      edArama.Text := yAdo.FieldByName(m_szSearchField).asstring;
      edArama.SelStart := l;
      edArama.SelLength := length(edArama.Text);
    End;
    yAdo.EnableControls;
  End;

End;

Procedure TfmFormClassDataList.FormShow(Sender : TObject);
Begin
  miEkle.Action := acEkle;
  miGuncelle.Action := acGuncelle;
  miKaydet.Action := acKaydet;
  miIncele.Action := acIncele;
  miSil.Action := acSil;
  miVazgec.Action := acVazgec;
  miKapat.Action := acKapat;
  miYenile.Action := acYenile;

  btSec.Action := acSec;
  btYeni.Action := acEkle;
  btDuzelt.Action := acGuncelle;
  btKaydet.Action := acKaydet;
  btIncele.Action := acIncele;
  btSil.Action := acSil;
  btVazgec.Action := acVazgec;

  Inherited;

  acSec.Visible := UseType = futSelect;

  If UseType = futSelect Then
    grdListe.SetFocus;

  If m_szSQLWhere <> '' Then
    acSimdiAra.Execute;
End;

Procedure TfmFormClassDataList.grdListeKeyDown(Sender : TObject;
  Var Key : Word; Shift : TShiftState);
Begin
  Inherited;

  If Key = VK_INSERT Then
    If (grdListe.DataSource.DataSet.Active) Then
      acEkle.Execute;
End;

Procedure TfmFormClassDataList.FormCreate(Sender : TObject);
Begin
  Inherited;
  DesingFormToTerminal;
End;

End.

